<template>
	<view class="page">
		<view class="weui-page__back">
			<image src="https://img.2024csnl.com/static/2.x/a97.png" mode="widthFix"></image>
		</view>
		<view class="user-info">
			<view class="inner">
				<view class="cover">
					<image :src="merchant.logo" mode=""></image>
				</view>
				<view class="exp">
					<view class="ut">
						<view class="name">
							<text>{{ merchant.name }}</text>
						</view>
						<view class="tag2">
							<image v-if="centerMsg.icon && centerMsg.icon[1]" :src="centerMsg.icon[1]" mode="heightFix"></image>
							<!-- <image v-if="centerMsg.levelid == 4" src="https://img.2024csnl.com/static/2.x/a114.png" mode="heightFix"></image>
							<image v-if="centerMsg.levelid == 3" src="https://img.2024csnl.com/static/2.x/a115.png" mode="heightFix"></image>
							<image v-if="centerMsg.levelid == 2" src="https://img.2024csnl.com/static/2.x/a116.png" mode="heightFix"></image>
							<image v-if="centerMsg.levelid == 1" src="https://img.2024csnl.com/static/2.x/a117.png" mode="heightFix"></image> -->
						</view>
						<!-- <view class="tag">
							<image src="https://img.2024csnl.com/static/2.x/a98.png" mode=""></image>
							<text>{{ '子公司股东' }}</text>
						</view> -->
					</view>
					<view
						class="uid"
						@click="onCopy(merchant.id)">
						<text>ID：{{ merchant.id }}</text>
					</view>
				</view>
			</view>
				
			<view
				class="link"
				@click="onSkip('/pages/tab/mine')">
				<image src="https://img.2024csnl.com/static/2.x/a33.png" mode=""></image>
				<text>个人端</text>
			</view>
		</view>
		
		<view class="account-info">
			<view class="money">
				<view class="label">
					<text>账户余额（￥）</text>
				</view>
				<view class="value">
					<text v-if="showMoney">{{ centerMsg.money }}</text>
					<text v-else>******</text>
				</view>
			</view>
			<view class="tao">
				<view class="row">
					<text>累计营业额</text>
					<text v-if="showMoney">¥{{ total_order_amount }}</text>
					<text v-else>******</text>
				</view>
				<view class="row">
					<text>累计收益</text>
					<text v-if="showMoney">¥{{ totalmoney }}</text>
					<text v-else>******</text>
				</view>
			</view>
			<view
				class="show"
				@click="changeShowMoney">
				<!-- <image src="https://img.2024csnl.com/static/2.x/a100.png" mode=""></image> -->
				<text v-if="showMoney">隐藏</text>
				<text v-else>显示</text>
			</view>
		</view>
		
		<view class="order-info">
			<view class="thead">
				<text>我的订单</text>
			</view>
			<view class="tbody">
				<view class="list">
					<view class="item">
						<view
							class="cell"
							@click="onSkip('/package/mine/businessOrder?pageType=0&bid=10')">
							<view class="icon">
								<image src="https://img.2024csnl.com/static/2.x/a93.png" mode="heightFix"></image>
								<text>0</text>
							</view>
							<view class="label">
								<text>待付款</text>
							</view>
						</view>
					</view>
					<view class="item">
						<view
							class="cell"
							@click="onSkip('/package/mine/businessOrder?pageType=1&bid=10')">
							<view class="icon">
								<image src="https://img.2024csnl.com/static/2.x/a94.png" mode="heightFix"></image>
								<text>0</text>
							</view>
							<view class="label">
								<text>待发货</text>
							</view>
						</view>
					</view>
					<view class="item">
						<view
							class="cell"
							@click="onSkip('/package/mine/businessOrder?pageType=2&bid=10')">
							<view class="icon">
								<image src="https://img.2024csnl.com/static/2.x/a95.png" mode="heightFix"></image>
								<text>0</text>
							</view>
							<view class="label">
								<text>待收货</text>
							</view>
						</view>
					</view>
					<view class="item">
						<view
							class="cell"
							@click="onSkip('/package/mine/businessOrder?pageType=3&bid=10')">
							<view class="icon">
								<image src="https://img.2024csnl.com/static/2.x/a96.png" mode="heightFix"></image>
								<text>0</text>
							</view>
							<view class="label">
								<text>待完成</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<view class="quick-info">
			<view class="thead">
				<text>商家工具</text>
			</view>
			<view class="tbody">
				<view class="list">
					<view
						v-for="(item, index) in quickList"
						:key="index"
						class="item">
						<view
							v-if="item.type === 'toast'"
							class="cell"
							@click="showToast('请使用微信的扫一扫')">
							<view class="icon">
								<image
									:src="item.icon"
									mode="">
								</image>
							</view>
							<view class="label">
								<text>{{ item.label }}</text>
							</view>
						</view>
						<view
							v-else
							class="cell"
							@click="onSkip(item.url, `bid=${merchant.id}`)">
							<view class="icon">
								<image
									:src="item.icon"
									mode="">
								</image>
							</view>
							<view class="label">
								<text>{{ item.label }}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		
		
		<!-- {{ merchant }} -->
		
		<!-- <view class="headerBox">
			<view>
				<view class="flex" style="align-items: center;">
					<view>
						<image class="header" mode="aspectFill" :src="merchant.logo"></image>
					</view>
					<view @click="onCopy(merchant.id)">
						<view class="shopName">{{merchant.name}}</view>
						<view class="idBox">SJID:{{merchant.id}}</view>
					</view>
				</view>
				<view class="qrCodeBigBox1">

				</view>
				<view class="qrCodeBigBox">
					<view v-if="false" style="display: flex; flex-direction: row;">
						<view class="flex abBtn2"></view>
						<view class="flex abBtn" @click="onChargeOff" style="margin-left: 5px;">
							<view class="qrBox flex">
								<image class="qrIcon" src="https://wx.2024csnl.com/static/mine/saoma.png" mode="">
								</image>扫码核销
							</view>
						</view>
					</view>

					<view style="display: flex; flex-direction: row; margin-top: 80rpx;">
						<view class="flex abBtn" v-if="false"
							@click="onSkip(`/business/pages/business_tab/face2FaceBusinessScanCodePay?bid=${merchant.id}`)">
							<view class="qrBox flex">
								<image class="qrIcon" src="https://wx.2024csnl.com/static/mine/saoma.png"></image>
								扫码收款
							</view>
						</view>
						<view v-if="merchant.collectioncode!=1" class="flex abBtn"
							@click="onSkip(`/package/mine/applicationCollectionCode?bid=${merchant.id}`)"
							style="margin-left: 5px;">
							<view class="qrBox flex">
								<image class="qrIcon" src="https://wx.2024csnl.com/static/mine/shoukuanm.png">
								</image>申请收款码
							</view>
						</view>
						<view v-if="merchant.collectioncode==1" class="flex abBtn"
							@click="onSkip(`/package/mine/businessMoneyCode?bid=${merchant.id}`)"
							style="margin-left: 5px;">
							<view class="qrBox flex">
								<image class="qrIcon" src="https://wx.2024csnl.com/static/mine/shoukuanm.png">
								</image>收款码
							</view>
						</view>
					</view>

				</view>
			</view>
		</view> -->
		
		<!-- <view class="msgBox" style="position: relative;">
			<view class="oneCard headerBtnBigBox">
				<view v-if="false" class="hintTit" @click="onSkip(`/package/mine/agreement?pageType=新手教程`)">新手教程</view>
				<view class="functionBox">
					<view v-if="item.isShow" class="oneBtn flex-center" v-for="(item,i) in skipList" :key="i"
						@click="onGoPage(item.url,item.name,item.type)">
						<view>
							<image :src="item.img"></image>
						</view>
						<view>{{item.name}}</view>
					</view>
				</view>
			</view>
			<view class="bgBox"></view>
			<view class="shareOption">
				<view class="shareOptionRow">
					<view class="shareOptionItem"
						@click="onSkip(`/package/mine/businessOrder?bid=${merchant.id}&startime=${today}&endtime=${endToday}`)">
						<view class="tit">今日订单数量</view>
						<view class="num">{{dayordercount}}</view>
					</view>
					<view class="shareOptionItem"
						@click="onSkip(`/package/mine/businessOrder?bid=${merchant.id}&startime=${today}&endtime=${endToday}`)">
						<view class="tit">今日订单金额</view>
						<view class="num">{{day_order_amount}}</view>
					</view>
					<view class="shareOptionItem"
						@click="onSkip(`/package/mine/businessOrder?bid=${merchant.id}&startime=${today}&endtime=${endToday}`)">
						<view class="tit">今日订单收益</view>
						<view class="num">{{daytotalmoney}}</view>
					</view>
				</view>
				<view style="height: 1px; background-color: #ddd; margin: 20rpx 0 30rpx;"></view>
				<view class="shareOptionRow">
					<view class="shareOptionItem"
						@click="onSkip(`/package/mine/businessOrder?bid=${merchant.id}&startime=2022-01-01&endtime=${endToday}`)">
						<view class="tit">历史订单数量</view>
						<view class="num">{{totalordercount}}</view>
					</view>
					<view class="shareOptionItem"
						@click="onSkip(`/package/mine/businessOrder?bid=${merchant.id}&startime=2022-01-01&endtime=${endToday}`)">
						<view class="tit">历史订单金额</view>
						<view class="num">{{total_order_amount}}</view>
					</view>
					<view class="shareOptionItem"
						@click="onSkip(`/package/mine/businessOrder?bid=${merchant.id}&startime=2022-01-01&endtime=${endToday}`)">
						<view class="tit">历史订单收益</view>
						<view class="num">{{totalmoney}}</view>
					</view>
				</view>
			</view>
			<view style="background: #fff;">
				<view class="between btnBigBox">
					<view :class="[{'activeColor':selectBtn==i}]" v-for="(item,i) in btnList" @click="onChangeBtn(i)">
						{{item}}
					</view>
				</view>
				<view class="searchBox flex">
					<image src="https://wx.2024csnl.com/static/mine/search.png"></image>
					<input v-model="searchText" placeholder="搜索商品" placeholder-class="placeholder" confirm-type="search"
						@confirm="onReset()" />
				</view>
				<view class="list">
					<order-list v-if="selectBtn==0" pageType="0" :list="list" :noMoreData="noMoreData"></order-list>
					<order-list v-else pageType="1" :list="list" :noMoreData="noMoreData"></order-list>
				</view>
			</view>
		</view> -->
		
	</view>
</template>

<script>
	import orderList from "./components/orderList.vue"
	import {
		merchantGoods,
		getPersonalCenter
	} from "../../api/index.js"
	export default {
		components: {
			orderList
		},
		data() {
			return {
				quickList: [
					{
						type: 'toast',
						url: '',
						icon: 'https://img.2024csnl.com/static/2.x/a87.png',
						label: '扫码核销'
					},
					{
						url: '/package/mine/businessOrder?pageType=0',
						icon: 'https://img.2024csnl.com/static/2.x/a88.png',
						label: '门店订单'
					},
					{
						url: '/package/we/pages/data2-center/index',
						icon: 'https://img.2024csnl.com/static/2.x/a89.png',
						label: '数据中心'
					},
					{
						url: '/business/pages/business_tab/storeManagement',
						icon: 'https://img.2024csnl.com/static/2.x/a90.png',
						label: '店铺管理'
					},
					{
						url: '/package/we/pages/business-goods/index',
						icon: 'https://img.2024csnl.com/static/2.x/a91.png',
						label: '进货管理'
					},
					{
						url: '/package/mine/businessMoneyCode',
						icon: 'https://img.2024csnl.com/static/2.x/a92.png',
						label: '申请收款码'
					}
				],
				skipList: [{
						name: '订单管理',
						img: 'https://wx.2024csnl.com/static/mine/dingdan-2.png',
						url: '/package/mine/businessOrder',
						isShow: true
					},
					{
						name: '余额',
						img: 'https://wx.2024csnl.com/static/mine/wallet-2.png',
						url: '/business/pages/business_tab/balanceWithdrawal?pageType=余额提现',
						type: true,
						isShow: true
					},
					{
						name: '余额明细',
						img: 'https://wx.2024csnl.com/static/mine/goumai-2.png',
						url: '/package/mine/moneyPurchase',
						isShow: true
					},
					{
						name: '余额互转',
						img: 'https://wx.2024csnl.com/static/mine/xitong-2.png',
						url: '/package/mine/transition/transition',
						isShow: false
					},
					{
						name: '店铺管理',
						img: 'https://wx.2024csnl.com/static/mine/dianpu-2.png',
						url: '/business/pages/business_tab/storeManagement',
						isShow: true
					},
					{
						name: '泌豆',
						img: 'https://wx.2024csnl.com/static/mine/tixian.png',
						url: '/business/pages/business_tab/balanceWithdrawal?pageType=泌豆提现',
						type: true,
						isShow: false
					},
					{
						name: '泌豆明细',
						img: 'https://wx.2024csnl.com/static/mine/goumai.png',
						url: '/package/mine/pointPurchase',
						isShow: false
					},
					{
						name: '泌豆互转',
						img: 'https://wx.2024csnl.com/static/mine/huzhuan.png',
						url: '/package/mine/transition/transition',
						isShow: false
					}
				],
				dayordercount: '-',
				daytotalmoney: '-',
				total_order_amount: '-',
				day_order_amount: '-',
				totalmoney: '-',
				totalordercount: '-',
				list: [],
				pagenum: 1,
				totalPage: '',
				optionNum: '',
				noMoreData: false,
				today: '',
				endToday: '',
				merchant: {},
				searchText: '',
				selectBtn: 0,
				btnList: ['出售中', '已下架'],
				systemBarHeight: getApp().globalData.systemBarHeight,
				givemoney: null,
				givescore: null,
				asyncHomeCheckLogin: false,
				intervalTimer: 0,
				showMoney: false,
				centerMsg: {}
			}
		},
		onLoad() {
			var endToday = new Date();
			endToday.setTime(endToday.getTime() + 24 * 60 * 60 * 1000);
			this.endToday = this.dateToYMD(endToday);
			this.today = this.dateToYMD(new Date())
			this.merchant = uni.getStorageSync('merchant')
			this.getMerchantGoods()
		},
		onReachBottom() {
			if (this.pagenum < this.totalPage) {
				this.pagenum += 1
				this.getMerchantGoods('bottom')
			} else {
				this.noMoreData = true
			}

		},
		onShow() {
			this.onGetPersonalCenter()
			this.onGetHomeCheckLogin()
			uni.$on('refish', () => {
				this.pagenum = 1
				this.getMerchantGoods()
			})
		},
		onHide() {
			console.log("hide")
			if (this.intervalTimer > 0) {
				clearInterval(this.intervalTimer);
			}
		},
		methods: {
			changeShowMoney () {
				this.showMoney = !this.showMoney
			},
			dateToYMD(date) {
				var d = date.getDate();
				var m = date.getMonth() + 1;
				var y = date.getFullYear();
				return '' + y + '-' + (m <= 9 ? '0' + m : m) + '-' + (d <= 9 ? '0' + d : d);
			},
			async onGetHomeCheckLogin() {
				let that = this;
				const res = await getPersonalCenter(`s=/ApiIndex/homechecklogin`)
				const {
					status,
					msg
				} = res.data
			
				if (status == 1) {
					this.asyncHomeCheckLogin = true;
					this.intervalTimer = setInterval(async () => {
						await this.onGetBobao();
					}, 10000);
				}
			},
			async onGetBobao() {
			
				const res = await getPersonalCenter(`s=/ApiBusiness/orderbobao`)
				const {
					yuying,
					status,
					msg
				} = res.data
			
				if (status == 1) {
					var plugin = requirePlugin("WechatSI");
					plugin.textToSpeech({
						lang: 'zh_CN',
						content: yuying,
						success: function(res) {
							if (res.retcode == 0) {
								let innerAudioContext = uni.createInnerAudioContext();
								innerAudioContext.autoplay = true; //自动播放
								innerAudioContext.loop = false; //循环播放
								innerAudioContext.src = `${res.filename}`;
								innerAudioContext.onPlay(() => { //可以播放事件
								});
								innerAudioContext.onError((res) => {});
								innerAudioContext.onstatechange = function() {
									console.log(innerAudioContext.state);
								};
							}
						}
					})
				}
			},
			async onGetPersonalCenter() {
				const res = await getPersonalCenter('s=/ApiZwyRequest/userinfo')
				const {
					data,
					status,
					msg
				} = res.data
				if (status == 1) {
					this.centerMsg = data
					this.merchant = this.centerMsg.business
					uni.setStorageSync('merchant', this.centerMsg.business)

				} else {
					this.showToast(msg)
				}
			},
			onGoPage(url, name, type) {
				if (name == '订单管理') {
					this.onSkip(`${url}?pageType=0&bid=${this.merchant.id}`)
				} else if (type) {
					this.onSkip(`${url}&bid=${this.merchant.id}`)
				} else if (name == '余额互转' || name == '泌豆互转') {
					let type = name == '余额互转' ? 0 : 1
					this.onSkip(`/package/mine/transition/transition?tabsActive=${type}&bid=${this.merchant.id}`)
				} else {
					this.onSkip(`${url}?bid=${this.merchant.id}`)
				}
			},
			getParam(path, name) {
				var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");
				if (reg.test(path))
					return unescape(RegExp.$2.replace(/\+/g, " "));
				return "";
			},
			// 扫码核销
			onChargeOff() {
				let that = this
				uni.scanCode({
					onlyFromCamera: true,
					autoZoom: false,
					success: (res) => {
						const co = this.getParam(res.result, "co");
						const type = this.getParam(res.result, "type");
						this.onSkip(`/business/pages/business_tab/chargeOff?type=${type}&co=${co}`)
					}
				});
			},
			// 商品列表
			async getMerchantGoods(type) {
				const res = await merchantGoods('s=/ApiBusiness/businessshop', {
					bid: this.merchant.id,
					status: this.selectBtn == 0 ? 1 : 0,
					search: this.searchText
				})
				const {
					givemoney,
					givescore,
					data,
					dayordercount,
					daytotalmoney,
					day_order_amount,
					totalmoney,
					total_order_amount,
					totalordercount,
					option_num,
					msg,
					status
				} = res.data
				if (status == 1) {
					this.givemoney = givemoney
					this.givescore = givescore
					var skipList = JSON.parse(JSON.stringify(this.skipList));
					skipList[3].isShow = givescore == 1;
					//skipList[7].isShow = givemoney == 1;
					this.skipList = skipList;

					this.optionNum = option_num
					this.totalPage = data.last_page
					this.dayordercount = dayordercount
					this.daytotalmoney = daytotalmoney
					this.day_order_amount = day_order_amount
					this.totalmoney = totalmoney
					this.total_order_amount = total_order_amount
					this.totalordercount = totalordercount
					type == 'bottom' ? this.list.push(...data.data) : this.list = data.data
					this.pagenum != 1 && data.data.length == 0 ? this.noMoreData = true : this.noMoreData = false

				} else {
					this.showToast(msg)
				}
			},
			// 复制
			onCopy(value) {
				uni.setClipboardData({
					data: value.toString(),
					success: () => {
						this.showToast('复制ID成功~')
					}
				});
			},
			onReset() {
				this.pagenum = 1
				this.list = []
				this.getMerchantGoods()
			},
			onChangeBtn(i) {
				this.selectBtn = i
				this.onReset()
			},

		}
	}
</script>

<style lang="scss" scoped>
	.user-info {
		position: relative;
		height: 500rpx;
		border-radius: 0 0 20rpx 20rpx;
		.inner {
			position: relative;
			display: flex;
			align-items: center;
			padding: 140rpx 20rpx 0;
		}
		.cover {
			image {
				display: block;
				width: 140rpx;
				height: 140rpx;
				border-radius: 50%;
				background-color: #E76730;
				border: 3px solid #fff;
			}
		}
		.exp {
			flex: 1;
			margin: 0 0 0 30rpx;
			position: relative;
			.ut {
				display: flex;
				align-items: center;
			}
		}
		.name {
			line-height: 40rpx;
			font-size: 36rpx;
			font-weight: bold;
			color: #fff;
		}
		.tag2 {
			margin-left: 20rpx;
			image {
				height: 40rpx;
			}
		}
		.tag {
			background: -webkit-linear-gradient(left, #FDD7A2, #ffffff);
			border-radius: 10rpx;
			display: flex;
			align-items: center;
			margin-left: 20rpx;
			padding: 8rpx 20rpx 8rpx 10rpx;
			image {
				display: block;
				width: 36rpx;
				height: 36rpx;
			}
			text {
				font-size: 28rpx;
				margin-left: 10rpx;
			}
		}
		.uid {
			margin: 20rpx 0 0;
			display: inline-block;
			padding: 10rpx 15rpx;
			border: 1px solid #ffffff;
			border-radius: 10rpx;
			color: #fff;
		}
		.link {
			position: absolute;
			right: 0;
			top: 40rpx;
			z-index: 2;
			display: flex;
			align-items: center;
			background: #fff;
			padding: 15rpx 20rpx 15rpx 20rpx;
			border-radius: 60rpx 0 0 60rpx;
			image {
				display: block;
				width: 40rpx;
				height: 40rpx;
			}
			text {
				margin-left: 10rpx;
				font-size: 28rpx;
			}
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	.page {
		position: relative;
		min-height: 100vh;
		background: #f8f8f8;
	}
	
	.account-info {
		position: relative;
		z-index: 2;
		background: url('https://img.2024csnl.com/static/2.x/a99.png') center center no-repeat #E76730;
		background-size: 100% 100%;
		margin: -160rpx 20rpx 0;
		border-radius: 20rpx;
		padding: 40rpx;
		color: #fff;
		.money {
			.label {
				line-height: 40rpx;
				font-size: 28rpx;
			}
			.value {
				line-height: 100rpx;
				font-size: 56rpx;
				font-weight: bold;
			}
		}
		.tao {
			margin: 40rpx 0 0;
			display: flex;
			align-items: center;
			.row {
				line-height: 40rpx;
				margin-right: 20rpx;
				text {
					font-size: 28rpx;
					margin-right: 10rpx;
					&:nth-child(1) {
						opacity: .5;
					}
				}
			}
		}
		.show {
			position: absolute;
			right: 0;
			top: 10rpx;
			z-index: 10;
			display: flex;
			align-items: center;
			padding: 30rpx;
			color: #fff;
			image {
				display: block;
				width: 40rpx;
				height: 40rpx;
				margin-right: 10rpx;
			}
			text {
				font-size: 28rpx;
			}
		}
	}
	
	
	.order-info {
		margin: 20rpx;
		background: #ffffff;
		border-radius: 20rpx;
		.thead {
			margin: 0 20rpx;
			height: 100rpx;
			line-height: 100rpx;
			font-size: 30rpx;
			font-weight: bold;
		}
		.tbody {
			.list {
				display: flex;
				align-items: center;
				text-align: center;
			}
			.item {
				width: 25%;
			}
			.cell {
				position: relative;
			}
			.icon {
				position: relative;
				display: inline-block;
				image {
					display: block;
					width: 70rpx;
					height: 70rpx;
				}
				text {
					position: absolute;
					right: 0;
					top: 0;
					padding: 2rpx 10rpx;
					background: #E76730;
					color: #fff;
					font-size: 24rpx;
					border-radius: 50%;
				}
			}
			.label {
				line-height: 60rpx;
			}
		}
	}
	
	.quick-info {
		margin: 20rpx;
		background: #ffffff;
		border-radius: 20rpx;
		.thead {
			margin: 0 20rpx;
			height: 100rpx;
			line-height: 100rpx;
			font-size: 30rpx;
			font-weight: bold;
		}
		.tbody {
			margin: -20rpx;
			.list {
				display: flex;
				flex-wrap: wrap;
			}
			.item {
				width: 33.33%;
			}
			.cell {
				position: relative;
				text-align: center;
				margin: 20rpx 0;
				.icon {
					image {
						width: 70rpx;
						height: 70rpx;
					}
				}
				.label {
					display: block;
					line-height: 60rpx;
					font-size: 28rpx;
				}
			}
		}
	}
	
</style>